package com.qf.web.serevlet;

import com.alibaba.fastjson.JSONArray;
import com.qf.service.GoodsTypeService;
import com.qf.service.impl.GoodsTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findgoodstypeservlet")
public class FindGoodsTypeServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");//设置编码
        response.setContentType("application/json;charset=utf-8");
        GoodsTypeService goodsTypeService = new GoodsTypeServiceImpl();
        List<String> names = goodsTypeService.findName();
        JSONArray jsonArray = new JSONArray();
        jsonArray.addAll(names);
        response.getWriter().print(jsonArray);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
